

* NOTE: randomization to tables is essential to distinguish causal from omitted variables sources of dependence.
* NOTE: the file persuasion_v12.dta DROPS all participants with either an invalid table number (e.g., zero) or if they have fewer than five people at their table.


use "persuasion_v12.dta"

* first, set up the balance test: (ideology, tmean and tsd are in persuasion_v12.dta):

capture drop ideology
polychoric  oboe_PR_DEF_TAXRICH oboe_PR_DEF_CUTPROG oboe_PR_DEF_ENTITLE oboe_PR_DEF_DEFENSE
polyfactor
predict ideology

centile ideology, centile(30, 60)
*				-- Binom. Interp. --
*Variable	Obs	Percentile	Centile	[95% Conf. Interval]
*ideology	2405	30	-1.539093	-1.551914   -1.322916
*					60	-.3115516	-.3511001   -.2759885

gen conservative = ideology>=(-.3115516)
gen liberal = ideology<=(-1.539093)
replace conservative=. if ideology==.
replace liberal=. if ideology==.


bysort sitetable: egen max_ideology=max( ideologyx)
bysort sitetable: egen min_ideology=min( ideologyx)
gen lib_atlibtable = max_ideology<0
gen con_atcontable = min_ideology>0

* tab sitetable if lib_atlibtable==1

*  sitetable |      Freq.     Percent        Cum.
* ------------+-----------------------------------
*         104 |          7        6.09        6.09
*         602 |          6        5.22       11.30
*        1103 |          5        4.35       15.65
*        1105 |          9        7.83       23.48
*        1108 |          7        6.09       29.57
*        1401 |          7        6.09       35.65
*        1403 |          7        6.09       41.74
*        1601 |          7        6.09       47.83
*        1842 |          7        6.09       53.91
*        1905 |          6        5.22       59.13
*        1906 |          6        5.22       64.35
*        1927 |          7        6.09       70.43
*        1932 |          7        6.09       76.52
*        1939 |          9        7.83       84.35
*        1940 |         10        8.70       93.04
*        1943 |          8        6.96      100.00
* ------------+-----------------------------------
*       Total |        115      100.00

*  tab sitetable if con_atcontable==1

*   sitetable |      Freq.     Percent        Cum.
* ------------+-----------------------------------
*        1806 |          7       12.28       12.28
*        1924 |          5        8.77       21.05
*        2007 |          9       15.79       36.84
*        2018 |         11       19.30       56.14
*        2121 |          7       12.28       68.42
*        2127 |          7       12.28       80.70
*        2403 |          5        8.77       89.47
*        2406 |          6       10.53      100.00
* ------------+-----------------------------------
*       Total |         57      100.00



capture drop tmean
capture drop tsd
gen tmean=.
gen tsd=.
forvalues i = 1/2793 {
qui summ sitetable if _n==`i'
local a r(mean)
qui summarize ideology if sitetable==`a' & _n!=`i'
local b r(mean)
local c r(sd)
qui replace tmean = `b' if _n==`i'
qui replace tsd = `c' if _n==`i'
}

xi: reg tmean black hispanic asian gradschool i.oboe_PR_SEX oboe_PR_AGE i.oboe_PR_FAMINC i.site
xi: reg tsd black hispanic asian gradschool i.oboe_PR_SEX oboe_PR_AGE i.oboe_PR_FAMINC i.site



polychoric oboe_PR_DEF_TAXBOTH oboe_PR_DEF_FEDSALES
polyfactor
predict nonideology





